package com.ruoyi.wechat.api;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.wechat.domain.Goods;
import com.ruoyi.wechat.domain.WxActivity;
import com.ruoyi.wechat.domain.WxScenicSpots;
import com.ruoyi.wechat.service.IGoodsService;
import com.ruoyi.wechat.service.IWxActivityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *
 * @author 李硕
 * @version 1.0
 */
@Api(value = "微信小程序API-营地商品管理", tags = {"微信小程序API-营地商品管理"})
@RestController
@RequestMapping("/wechat/goods")
public class WxGoodsController extends BaseController {

    @Autowired
    private IGoodsService iGoodsService;

    @ApiOperation(value = "根据营地Id获取该营地下的商品列表", response = Goods.class)
    @GetMapping("/getGoodsByCampId/{campId}")
    public AjaxResult getGoodsByCampId(@PathVariable("campId") String campId) {
        if (campId == null) {
            return error("营地Id不能为空");
        }
//        Goods goods = new Goods();
//        goods.setCampId(campId);
        List<Goods> list = iGoodsService.selectGoodsByCampId(campId);
        System.out.println("-----------------------------");
        System.out.println(list);
        System.out.println("campId="+campId);
        return success(list);
    }


    @ApiOperation(value = "添加商品并提交审批")
    @Log(title = "微信小程序API-营地商品管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody Goods goods){
        System.out.println("goodsAdd="+goods);
        if (goods == null) {
            return error("数据不能为空");
        }
        if (goods.getCampId() == null) {
            return error("营地Id不能为空");
        }
        if (goods.getGoodsName() == null) {
            return error("景点名称不能为空");
        }
        if (goods.getGoodsImg() == null ) {
            return error("图片不能为空");
        }
        if (goods.getGoodsPrice() == null) {
            return error("价格不能为空");
        }
        goods.setGoodsId(IdUtils.randomUUID());
        return toAjax(iGoodsService.insertGoods(goods));
    }

    @ApiOperation(value = "根据商品Id完成删除")
    @Log(title = "微信小程序API-营地商品管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/delete/{goodsId}")
    public AjaxResult delete(@PathVariable("goodsId") String goodsId){
        if (goodsId == null) {
            return error("商品Id不能为空");
        }
        return toAjax(iGoodsService.deleteGoodsByGoodsId(goodsId));
    }


}
